// Copyright Up and Running var acctModule = require("../../server/account"); describe("An Account Manager", function () { beforeEach(function() { this.accountManager = acctModule.accountManager(); }); afterEach(function() { this.accountManager = null; }); it("should return an account object when it is asked for", function () { var account = this.accountManager.getAccount(123); expect(account.accountKey).toBe(123); }); it("should track accounts and allow their values to change and still maintain their reference", function() { var account = this.accountManager.getAccount(123); expect(account.accountKey).toBe(123); account.foo = 'bar'; var new_account = this.accountManager.getAccount(123); expect(new_account.foo).toBe('bar'); }); it("can track multiple accounts and fetch the appropriate one when needed", function () { var account1 = this.accountManager.getAccount(123); var account2 = this.accountManager.getAccount(124); expect(account1.accountKey).toBe(123); expect(account2.accountKey).toBe(124); }); }); describe("An Account", function () { var key = 123; beforeEach(function() { var am = acctModule.accountManager(); this.account = am.getAccount(key); }); afterEach(function() { this.account = null; }); it("should initially have 0 devices", function() { expect(this.account.registeredDeviceCount()).toEqual(0); }); it("should be able to generate a device GUID", function() { var guid = this.account.generateDeviceUUID(); expect(guid).toBeDefined(); expect(guid).toBeTruthy(); }); it("UUIDs generated should be random and unique", function () { var uuids = Array(); for (i = 0; i < 1000; i++) { uuids.push(this.account.generateDeviceUUID()); } expect(uuids.length).toEqual(1000); // assign a unique method to the array uuids.unique = function() { var o = {}, i, l = this.length, r = []; for(i=0; i